package com.test.xshang.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @BelongsProject: simpleframework
 * @BelongsPackage: com.Xshang.reflect
 * @Author: xshang
 * @CreateTime: 2023-06-23  20:53
 * @Description: 通过反射获取对象的方法并执行
 * @Version: 1.0
 */
public class MethodCollector {

    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
        Class clazz = Class.forName("com.test.xshang.reflect.ReflectTarget");

        ReflectTarget reflectTarget = (ReflectTarget) clazz.newInstance();

        Method[] declaredMethods = clazz.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod);
            declaredMethod.invoke(reflectTarget);
        }




    }
}
